package com.resource.project.controller.system;

import com.resource.project.entity.RespBean;
import com.resource.project.os.AskToken;
import com.resource.project.os.LoginVo;
import com.resource.project.service.system.service.ILoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "处理用户登陆")
@RestController
public class LoginController {

    @Autowired
    private ILoginService iLoginService;

    @ApiOperation(value = "登陆方法")
    @GetMapping("/login")
    public RespBean hello(){
        return RespBean.error("尚未登陆，请先登录");
    }

    @PostMapping({"/getTokenByLogin"})
    @ApiOperation("登录获取token")
    public RespBean getToken(@RequestBody LoginVo loginVM) {
        AskToken askToken = this.iLoginService.getAskTokenByLogin(loginVM);
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add("Authorization", "Bearer " + askToken.getIdToken());
        return RespBean.ok(askToken);
    }

}
